local snow = require("meet_your_mods.mhr").snow

snow.enemy.EnemyDef.EmTypes:fetch_enum("none", "EmTypeNoData")
snow.data.ContentsIdSystem.ItemId:fetch_enum("none", "I_Unclassified_None")
snow.data.DataDef.PlEquipSkillId:fetch_enum("none", "Pl_EquipSkill_None")

snow.data.ItemBox:fetch_method("try_add_item", "tryAddGameItem(snow.data.ContentsIdSystem.ItemId, System.Int32)")
snow.data.DataShortcut:fetch_method("get_item_name", "getName(snow.data.ContentsIdSystem.ItemId)")
snow.data.DataShortcut:fetch_method("get_player_equipment_skill_name", "getName(snow.data.DataDef.PlEquipSkillId)")
snow.data.DataShortcut:fetch_method("get_talisman_name", "getName(snow.data.DataDef.PlTalismanId)")
snow.data.DataShortcut:fetch_method("get_armor_name", "getName(snow.data.DataDef.PlArmorId)")

local shortcut = {
    data_manager    = nil,
    message_manager = nil,

    money         = nil,
    item_box      = nil,
    equipment_box = nil,
    point         = nil,
}

--获取玩家装备技能名称
function shortcut:get_equipment_skill_name(skill)
    return snow.data.DataShortcut:get_player_equipment_skill_name(skill)
end

--获取护石名称
function shortcut:get_talisman_name(talisman)
    return snow.data.DataShortcut:get_talisman_name(talisman)
end

--检测dlc护石
function shortcut:is_dlc_talisman(talisman)
    return snow.data.DataShortcut:isDlcTalisman(talisman)
end

--获取物品箱
function shortcut:get_item_inventory()
    self:fetch_data_instance()
    return self.item_box._InventoryList
end

--获得物品数量
function shortcut:get_item_quantity(item)
    return snow.data.DataShortcut:getCountOfAll(item)
end

--获得物品名称
function shortcut:get_item_name(item)
    return snow.data.DataShortcut:get_item_name(item)
end

--获得物品类型
function shortcut:get_item_type(item)
    return snow.data.DataShortcut:getItemType(item)
end

--获取装备箱
function shortcut:get_equipment_inventory()
    self:fetch_data_instance()
    return self.equipment_box:get_NonFilteredWeaponArmorInventoryList()
end

--获取装备系列
function shortcut:get_equipment_series(series)
    return snow.data.DataShortcut:getSeriesData(series)
end

--获取装备名称
function shortcut:get_armor_name(armor)
    return snow.data.DataShortcut:get_armor_name(armor)
end

--向储物箱添加物品
function shortcut:add_item_to_box(item, quantity, show_system_message)
    quantity = quantity or 1
    if quantity <= 0 then
        return
    end
    shortcut:fetch_data_instance()

    local space  = snow.data.DataShortcut:getRemainingCountInBox(item)
    local to_add = quantity <= space and quantity or space

    --出售多余的物品
    if quantity > space then
        self.money:addMoney(snow.data.DataShortcut:getSellPrice(item) * (quantity - to_add))
    end

    if show_system_message then
        snow.data.DataShortcut:addItemToBox(item, quantity)
    else
        self.item_box:try_add_item(item, to_add)
    end
end

--消耗物品
function shortcut:consume_item(item, quantity)
    snow.data.DataShortcut:consumeItem(item, quantity or 1)
end

--获取点数
function shortcut:get_point()
    self:fetch_data_instance()
    return self.point:get_Point()
end

--消费点数
function shortcut:consume_point(quantity)
    if quantity <= 0 then
        return
    end
    self:fetch_data_instance()
    self.point:subPoint(quantity)
end

function shortcut:fetch_data_instance()
    if self.data_manager then
        return true
    end

    self.data_manager = snow.data.DataManager:get_singleton()
    if self.data_manager then
        self.item_box      = self.data_manager:getItemBox()
        self.equipment_box = self.data_manager:get_EquipBoxData()
        self.money         = self.data_manager:getHandMoney()
        self.point         = self.data_manager:get_VillagePointData()
        return true
    end

    return false
end

--获得地图名称
function shortcut:get_map_name(map)
    if snow.QuestMapManager.MapNoType.None == map then
        return nil
    end
    self:fetch_message_instance()
    return self.message_manager:getMapNameMessage(map)
end

--获得怪物名称
function shortcut:get_enemy_name(enemy)
    if snow.enemy.EnemyDef.EmTypes.none == enemy then
        return nil
    end
    self:fetch_message_instance()
    return self.message_manager:getEnemyNameMessage(enemy)
end

--检测是否为大型怪物
function shortcut:is_boss_enemy(enemy)
    return snow.enemy.EnemyDef:isBoss(enemy)
end

--检测是否允许捕获
function shortcut:is_enable_capture(enemy)
    return snow.enemy.EnemyDef:isEnableCapture(enemy)
end

function shortcut:fetch_message_instance()
    if not self.message_manager and snow.gui.MessageManager:get_singleton() then
        self.message_manager = snow.gui.MessageManager:get_singleton()
    end
end

function shortcut:initialize()
end

return shortcut
